<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<head>
    <title>用户个人信息页</title>
    <!-- Custom Theme files -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
    <link href="${css}/bootstrap.css" type="text/css" rel="stylesheet" media="all">
    <link href="${css}/style2.css" type="text/css" rel="stylesheet" media="all">
    <script src="${js}/jquery.js"></script>
    <script type="text/javascript" src="${js}/bootstrap-3.1.1.min.js"></script>
    <script src="${js}/simpleCart.min.js"> </script>
    <script src="${root}/resource/layer/layer.js"></script>
</head>
<body>
<%--消息--%>
<div id="div_3" style="position: absolute; display: none;z-index: 8;">
    <h2 id="message"></h2>
</div>
<%--消息--%>
<script src="${js}/mc.js"></script>
<%--Login--%>
<!--header-->
<div class="header">
    <div class="container">
        <nav class="navbar navbar-default" role="navigation">
            <div class="navbar-header">
                <h1 class="navbar-brand"><a  href="#">My-BookStore</a></h1>
            </div>
            <!--navbar-header-->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li><a href="${root}/user/front/indexView" class="active">首页</a></li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">类型<b class="caret"></b></a>
                        <ul class="dropdown-menu multi-column">
                            <li><a class="list" href="${root}/book/front/list">全部</a></li>
                            <c:forEach items="${categorys}" var="category">
                                <li><a class="list" href="${root}/book/front/list?cid=${category.cid}" name="${category.cid}">${category.cname}</a></li>
                            </c:forEach>
                        </ul>
                    </li>
                    <li class="dropdown grid">
                        <a href="${root}/user/front/userinfo" class="list1" >个人中心</a>
                    </li>
                    <li class="dropdown grid">
                        <a href="${root}/user/front/cart" class="list1">购物车</a>
                    </li>
                    <li class="dropdown grid">
                        <a href="${root}/orders/user/orderList" class="list1">订单</a>
                    </li>
                </ul>
                <!--/.navbar-collapse-->
            </div>
            <!--//navbar-header-->
        </nav>
        <div class="header-info">
            <div class="header-right login" id="login-div">
                <a href="#"><span class="glyphicon glyphicon-user" aria-hidden="true"></span></a>
                <c:if test="${not empty userLogin}">
                    <div id="loginBox">
                        <form id="loginForm" style="padding: 10px 10px">
                            <h4>用户名:${userLogin.username}</h4>
                            <button class="btn btn-info"><a href="#">个人中心</a></button><br/>
                            <button id="btn5" class="btn btn-danger">退出登录</button><br/>
                        </form>
                    </div>
                </c:if>
            </div>
            <div class="header-right cart" id="cart-div">
                <a href="${root}/user/front/cart"><span class="glyphicon glyphicon-shopping-cart" aria-hidden="true"></span></a>
            </div>
        </div>
        <script>
            $(function () {
                $("#btn5").click(function () {
                    $.ajax({
                        url:"${root}/user/front/return",
                        type:"get",
                        success:function (response) {
                            if (response.result==200){
                                showInfo();
                                $("#message").text("退出成功！");
                                setTimeout(function () {
                                    hideInfo();
                                    $("#message").text("");
                                    location.href("${root}/user/front/indexView");
                                },1000);
                            }
                        }
                    })
                });
            })
        </script>
    </div>
</div>
<!--//header-->
<div class="container">
    <div class="row clearfix">
        <div class="col-md-2 column">
            <div class="list-group">
                <a href="${root}/user/front/userinfo" class="list-group-item">用户信息页</a>
                <a href="${root}/user/front/address" class="list-group-item">收货地址设置</a>
                <a href="${root}/orders/user/orderList" class="list-group-item">用户订单信息</a>
            </div>
            <script>
                $(function(){
                    $("a").click(function(){
                        $("a").removeClass("active");
                        $(this).addClass("active");
                    });
                })
            </script>
        </div>
        <div class="col-md-5 column">
            <h3 class="text-center text-info">
                用户详细信息
            </h3>
            <form class="form-horizontal" role="form" id="info">
                <input type="hidden" name="uid" id="uid1" >
                <input type="hidden" name="username" id="username1">
                <input type="hidden" name="password" id="password1">
                <div class="form-group">
                    <label class="col-sm-3 control-label">真实姓名</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="realname" name="realname" /><span id="realnameError"></span>
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-3 control-label">电话</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="phone" name="phone" /><span id="phoneError"></span>
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-3 control-label">地址</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="address" name="address" /><span id="addressError"></span>
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-3 control-label">邮箱</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="email" name="email" /><span id="emailError"></span>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-3 col-sm-8">
                        <button id="btn-info" type="button" class="btn btn-default">修改</button>
                    </div>
                </div>
            </form>
            <script>
                $(function () {
                    $.ajax({
                        url:"${root}/user/front/find",
                        type: "post",
                        data:{"uid":${userLogin.uid}},
                        dataType:"json",
                        success:function (response) {
                            if (response.code==200){
                                $("#uid1").val(response.data.uid);
                                $("#username1").val(response.data.username);
                                $("#password1").val(response.data.password);
                                $("#realname").val(response.data.realname);
                                $("#phone").val(response.data.phone);
                                $("#email").val(response.data.email);
                                $("#address").val(response.data.address);

                                $("#uid2").val(response.data.uid);
                                $("#username").val(response.data.username);
                                $("#username2").val(response.data.username);
                                $("#realname2").val(response.data.realname);
                                $("#phone2").val(response.data.phone);
                                $("#email-1").val(response.data.email);
                                $("#email-2").val(response.data.email);
                                $("#address2").val(response.data.address);
                            }else{
                                alert(response.message);
                            }
                        }
                    });
                    $("#btn-info").click(function () {
                        $.ajax({
                            url:"${root}/user/front/update1",
                            type: "post",
                            data:$("#info").serialize(),
                            dataType:"json",
                            success:function (response) {
                                if (response.code==200){
                                    $("#realname").val(response.data.realname);
                                    $("#phone").val(response.data.phone);
                                    $("#email").val(response.data.email);
                                    $("#address").val(response.data.address);

                                    $("#realname2").val(response.data.realname);
                                    $("#phone2").val(response.data.phone);
                                    $("#email-1").val(response.data.email);
                                    $("#email-2").val(response.data.email);
                                    $("#address2").val(response.data.address);
                                    showInfo();
                                    $("#message").text("修改成功！");
                                    setTimeout(function () {
                                        hideInfo();
                                        $("#message").text("");
                                    },3000);
                                    $("#realnameError").text("");
                                    $("#phoneError").text("");
                                    $("#emailError").text("");
                                    $("#addressError").text("");
                                }else if(response.code==300){
                                    $("#realnameError").text(response.data.realnameError);
                                    $("#phoneError").text(response.data.phoneError);
                                    $("#emailError").text(response.data.emailError);
                                    $("#addressError").text(response.data.addressError);
                                    showInfo();
                                    $("#message").text("信息有空值！");
                                    setTimeout(function () {
                                        hideInfo();
                                        $("#message").text("");
                                    },3000);
                                }else {
                                    alert(response.message);
                                    showInfo();
                                    $("#message").text("修改失败！");
                                    setTimeout(function () {
                                        hideInfo();
                                        $("#message").text("");
                                    },3000);
                                }
                            }
                        });
                    });
                })
            </script>
        </div>
        <div class="col-md-5 column">
            <h3 class="text-center text-warning">
                用户登录信息
            </h3>
            <form class="form-horizontal" role="form" id="info2">
                <input type="hidden" name="uid" id="uid2">
                <input type="hidden" name="username"  id="username2">
                <input type="hidden" name="realname" id="realname2">
                <input type="hidden" name="phone" id="phone2">
                <input type="hidden" name="address" id="address2">
                <input type="hidden" name="email" id="email-2">
                <div class="form-group">
                    <label  class="col-sm-2 control-label">账号</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="username" name="username" disabled/>
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-2 control-label">原密码</label>
                    <div class="col-sm-8">
                        <input type="password" class="form-control" id="password" name="oldpassword"/><span id="oldusernameError"></span>
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-2 control-label">新密码</label>
                    <div class="col-sm-8">
                        <input type="password" class="form-control" id="password2" name="password"/><span id="passwordError"></span>
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-2 control-label">邮箱</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" name="email" id="email-1" disabled><button type="button" id="btn3">获取验证码</button><span id="emailinfoError"></span>
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-2 control-label">验证码</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="code" name="code1" placeholder="修改账号密码需要先获取验证码....."/><span id="codeError"></span>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-8">
                        <button type="button" id="btn-info2" class="btn btn-default">修改</button>
                    </div>
                </div>
            </form>
            <script>
                $(function () {

                    $("#btn3").click(function () {
                        let email = $("#email-1").val();
                        $.ajax({
                            url:"${root}/user/front/email",
                            type: "post",
                            data:{"email":email},
                            dataType: "json",
                            success:function (response) {
                                if (response.result==200){
                                    $("#emailinfoError").text("发送成功，请立即输入");
                                }else{
                                    $("#emailinfoError").text("邮箱不存在");
                                }
                            }
                        });
                        $("#btn3").attr({"disabled":"disabled"});
                        let o1 = new Date().getTime();
                        let seconds = 5;
                        let id = setInterval(function () {
                            let o2 = new Date().getTime();
                            let time = o2 - o1;
                            $("#btn3").text("还剩"+(seconds--)+"秒,可以再次请求验证码");
                            if (time>=5000){
                                $("#btn3").removeAttr("disabled");
                                $("#btn3").text("发送验证码");
                                clearInterval(id);
                            }
                        },1000);
                    });

                    $("#btn-info2").click(function () {
                        $.ajax({
                            url:"${root}/user/front/update2",
                            type: "post",
                            data:$("#info2").serialize(),
                            dataType:"json",
                            success:function (response) {
                                if (response.code==200){
                                    $("#password1").val(response.data.password);
                                    showInfo();
                                    $("#message").text("修改成功！");
                                    setTimeout(function () {
                                        hideInfo();
                                        $("#message").text("");
                                    },3000);
                                    $("#passwordError").text("");
                                    $("#oldusernameError").text("");
                                    $("#codeError").text("");
                                }else if(response.code==300){
                                    $("#passwordError").text(response.data.passwordError);
                                    showInfo();
                                    $("#message").text("密码为空！");
                                    setTimeout(function () {
                                        hideInfo();
                                        $("#message").text("");
                                    },3000);
                                }else if(response.code==302){
                                    $("#oldusernameError").text(response.message);
                                    showInfo();
                                    $("#message").text("原密码错误！");
                                    setTimeout(function () {
                                        hideInfo();
                                        $("#message").text("");
                                    },3000);
                                }else if(response.code==303){
                                    $("#codeError").text(response.message);
                                    showInfo();
                                    $("#message").text("验证码错误！");
                                    setTimeout(function () {
                                        hideInfo();
                                        $("#message").text("");
                                    },3000);
                                }
                            }
                        });
                    });
                })
            </script>
        </div>
    </div>
</div>
<!--footer-->
<div class="footer">
    <div class="container">
        <div class="footer-grids">
            <div class="col-md-2 footer-grid">
                <h4>公司</h4>
                <ul>
                    <li><a href="#">工作地点</a></li>
                    <li><a href="#">团队</a></li>
                    <li><a href="#">事件</a></li>
                    <li><a href="#">经销商</a></li>
                </ul>
            </div>
            <div class="col-md-2 footer-grid">
                <h4>业务</h4>
                <ul>
                    <li><a href="#">赞助</a></li>
                    <li><a href="#">常见问题</a></li>
                    <li><a href="#">担保</a></li>
                    <li><a href="contact.html">联系我们</a></li>
                </ul>
            </div>
            <div class="col-md-3 footer-grid">
                <h4>订单 & 退货</h4>
                <ul>
                    <li><a href="#">订单状态</a></li>
                    <li><a href="#">配送方式</a></li>
                    <li><a href="#">退换货说明</a></li>
                    <li><a href="#">电子卡片</a></li>
                </ul>
            </div>
            <div class="col-md-2 footer-grid">
                <h4>法律</h4>
                <ul>
                    <li><a href="#">隐私</a></li>
                    <li><a href="#">条款和条件</a></li>
                    <li><a href="#">社会责任</a></li>
                </ul>
            </div>
            <div class="col-md-3 footer-grid icons">
                <h4>与我们联系</h4>
                <ul>
                    <li><a href="#"><img src="${images}/i1.jpg" alt=""/>在Wechat上关注我们</a></li>
                    <li><a href="#"><img src="${images}/i2.jpg" alt=""/>在微博上关注我们</a></li>
                    <li><a href="#"><img src="${images}/i3.jpg" alt=""/>在QQ上关注我们</a></li>
                </ul>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>
</div>
<div class="footer-bottom">
    <div class="container">
        <p>Copyright &copy; 2021.Company name MINE.More Software <a href="http://www.1127009780@qq.com/" target="_blank" title="fcx的Home">fcx的Home</a>.</p>
    </div>
</div>
</body>
</html>
